<template>
	<view class="hotel-details-page">
		<!-- 头部图片和覆盖层 -->
		<view class="hotel-header">
			<view class="hotel-image-container">
				<image class="hotel-image"
					src="https://hilton-duoladuo.oss-cn-shenzhen.aliyuncs.com/basic-common/upload/680aea75463da387fd39ef11.jpg"
					mode="aspectFill">
				</image>
				<view class="image-overlay"></view>
			</view>

			<!-- 酒店基本信息区域（覆盖在图片上） -->
			<view class="hotel-info-overlay">
				<view class="hotel-name">{{hotelDetail.name}}</view>

				<view class="glass-container">
					<view class="hotel-basic-info">
						<view class="info-row">
							<view class="info-item">
								<text class="info-label">开业时间</text>
								<text class="info-value">{{openYear}}年</text>
							</view>
							<view class="info-item">
								<text class="info-label">房间数量</text>
								<text class="info-value">{{roomsQuantity}}间</text>
							</view>
						</view>

						<view class="info-row">
							<view class="info-item">
								<text class="info-label">酒店等级</text>
								<text class="info-value">
									<text class="diamond" v-for="(item, index) in starLevel" :key="index">♦</text>
									<uni-icons type="help" size="16" color="rgba(255,255,255,0.6)"></uni-icons>
								</text>
							</view>
							<view class="info-item">
								<text class="info-label">携程优选</text>
								<!-- <text class="info-value">
									<text class="ctrip">C</text>
									<uni-icons type="help" size="16" color="rgba(255,255,255,0.6)"></uni-icons>
								</text> -->
							</view>
						</view>

						<view class="divider"></view>

						<view class="info-row">
							<view class="info-item phone-item">
								<text class="info-label">酒店电话</text>
								<text class="info-value phone-value">{{deskPhone}}</text>
								<view class="phone-icon" @click="callPhone">
									<uni-icons type="phone" size="20" color="#fff"></uni-icons>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 选项卡区域 -->
		<view class="tabs-container">
			<view class="tabs">
				<view class="tab-item" :class="{ active: activeTab === 'introduction' }"
					@click="switchTab('introduction')">
					酒店亮点
				</view>
				<view class="tab-item" :class="{ active: activeTab === 'facilityServices' }"
					@click="switchTab('facilityServices')">
					设施服务
				</view>
				<view class="tab-item" :class="{ active: activeTab === 'policy' }" @click="switchTab('policy')">
					酒店政策
				</view>
			</view>

			<!-- 选项卡内容 -->
			<view class="tab-content">
				<rich-text v-if="activeTab === 'introduction'" :nodes="info.introduction"></rich-text>
				<rich-text v-if="activeTab === 'facilityServices'" :nodes="info.facilityServices"></rich-text>
				<rich-text v-if="activeTab === 'policy'" :nodes="info.policy"></rich-text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		hotelDetail,
		getByType
	} from "../../api/hotel"

	export default {
		data() {
			return {
				hotelDetail: {},
				info: {
					introduction: '',
					facilityServices: '',
					policy: ''
				},
				activeTab: 'introduction', // 默认选中第一个选项卡
				isLoadIntroduction: false,
				isLoadPolicy: false,
				isLoadFacility: false
			};
		},
		onLoad(options) {
			this.getHotelDetail()
			this.getContent(6)
		},
		computed: {
			openYear() {
				return this.hotelDetail.openingDate ? this.hotelDetail.openingDate.substring(0, 4) : ''
			},
			roomsQuantity() {
				return this.hotelDetail.roomsQuantity
			},
			deskPhone() {
				return this.hotelDetail.deskPhone
			},
			// policy() {
			// 	return this.hotelDetail.policy
			// },
			// facilityServices() {
			// 	return this.hotelDetail.facilityServices
			// },
			// introduction() {
			// 	return this.hotelDetail.introduction
			// },
			starLevel() {
				return this.hotelDetail.starLevel || 0
			}
		},
		methods: {
			async getHotelDetail() {
				try {
					const res = await hotelDetail()
					const {
						data
					} = res
					this.hotelDetail = data
				} catch (err) {
					console.log(err)
				}
			},
			switchTab(tabName) {
				this.activeTab = tabName
				if (this.activeTab == "introduction" && this.isLoadIntroduction == false) {
					this.getContent(6)
					this.isLoadIntroduction = true
				} else if (this.activeTab == "facilityServices" && this.isLoadFacility == false) {
					this.getContent(7)
					this.isLoadFacility = true
				} else if (this.activeTab == "policy" && this.isLoadPolicy == false) {
					this.getContent(8)
					this.isLoadPolicy = true
				}
			},
			callPhone() {
				if (this.deskPhone) {
					uni.makePhoneCall({
						phoneNumber: this.deskPhone
					})
				}
			},
			async getContent(type) {
				getByType({
					type: type
				}).then((res) => {
					const {
						data
					} = res

					if (type == 6) {
						this.info.introduction = data.content
					} else if (type == 7) {
						this.info.facilityServices = data.content
					} else if (type == 8) {
						this.info.policy = data.content
					}
				}).catch((err) => {
					console.log(err)
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.hotel-details-page {
		background-color: #fff;
		min-height: 100vh;
		height: 100vh;
		overflow: hidden;
		display: flex;
		flex-direction: column;
	}

	.hotel-header {
		position: relative;
		min-height: 290rpx;
		height: auto;
		margin-bottom: -20rpx;
		flex-shrink: 0;
	}

	.hotel-image-container {
		width: 100%;
		height: 100%;
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;

		.hotel-image {
			width: 100%;
			height: 100%;
			object-fit: cover;
			filter: blur(2px);
		}

		.image-overlay {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.6));
		}
	}

	.hotel-info-overlay {
		position: relative;
		z-index: 1;
		color: #fff;
		padding: 20rpx 30rpx 40rpx 30rpx;
		display: flex;
		flex-direction: column;

		.hotel-name {
			font-size: 46rpx;
			font-weight: bold;
			margin-bottom: 20rpx;
			text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
		}

		.glass-container {
			background: rgba(0, 0, 0, 0.2);
			backdrop-filter: blur(10px);
			border-radius: 16rpx;
			overflow: hidden;
			border: 1rpx solid rgba(255, 255, 255, 0.1);
			padding: 32rpx 28rpx;
		}

		.hotel-basic-info {
			display: flex;
			flex-direction: column;

			.info-row {
				display: flex;
				margin-bottom: 15rpx;
				justify-content: space-between;

				&:last-child {
					margin-bottom: 0;
				}

				.info-item {
					display: flex;
					align-items: center;
					min-width: 40%;

					.info-label {
						opacity: 0.6;
						margin-right: 10rpx;
						font-size: 26rpx;
						white-space: nowrap;
					}

					.info-value {
						display: flex;
						align-items: center;
						font-size: 26rpx;
						white-space: nowrap;
					}

					.diamond {
						color: #FFD700;
						font-size: 20rpx;
						padding-right: 4rpx;
					}

					.ctrip {
						background-color: #ff6633;
						color: white;
						font-size: 18rpx;
						width: 28rpx;
						height: 28rpx;
						border-radius: 4rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						margin-right: 8rpx;
						font-weight: bold;
					}
				}

				.phone-item {
					flex: 1;

					.phone-value {
						flex: 1;
					}

					.phone-icon {
						width: 40rpx;
						height: 40rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						background: rgba(255, 255, 255, 0.2);
						border-radius: 50%;
					}
				}
			}

			.divider {
				height: 1rpx;
				background: rgba(255, 255, 255, 0.2);
				margin: 10rpx 0 20rpx;
			}
		}
	}

	.tabs-container {
		background-color: #fff;
		border-radius: 20rpx 20rpx 0 0;
		position: relative;
		z-index: 2;
		overflow: hidden;
		display: flex;
		flex-direction: column;
		flex: 1;

		.tabs {
			display: flex;

			.tab-item {
				flex: 1;
				text-align: center;
				padding: 20rpx 0;
				font-size: 28rpx;
				position: relative;
				color: #666;

				&.active {
					color: #333;
					font-weight: bold;

					&:after {
						content: '';
						position: absolute;
						left: 50%;
						bottom: 0;
						transform: translateX(-50%);
						width: 60rpx;
						height: 4rpx;
						background-color: #1976D2;
					}
				}
			}
		}

		.tab-content {
			padding: 30rpx 30rpx 50rpx 30rpx;
			flex: 1;
			overflow-y: auto;
			-webkit-overflow-scrolling: touch;
		}
	}
</style>